<?php
/**
 * Object Relational Persistence Mapping Class for table: odonto_stomatology_encounter
 *
 * @package	com.athena
 * @author	LHV
 */
class EmrGeneralExamination2 extends ORDataObject {

	/**#@+
     * Fields of table: emr_general_examination_2 mapped to class members
     */
    var $emr_general_examination_2_id       = '';
    var $medical_record_id      = '';
    var $ly_do_kham     = '';
    var $benh_su        = '';
    var $di_ung     = '';
    var $than_kinh_kham     = '';
    var $than_kinh_benh_ly      = '';
    var $toan_trang_kham        = '';
    var $toan_trang_benh_ly     = '';
    var $tuan_hoan_kham     = '';
    var $tuan_hoan_benh_ly      = '';
    var $ho_hap_kham        = '';
    var $ho_hap_benh_ly     = '';
    var $tieu_hoa_kham      = '';
    var $tieu_hoa_benh_ly       = '';
    var $tiet_nieu_kham     = '';
    var $tiet_nieu_benh_ly      = '';
    var $tien_luong     = '';
    var $summary        = '';
    var $diagnosis      = '';
    var $primary_icd10      = '';
    var $secondary_icd10_1      = '';
    var $secondary_icd10_2      = '';
    var $note       = '';
    var $doctor_id      = '';
    var $doctor_updated_id      = '';
    var $encounter_date     = '';
    var $last_updated       = '';
    /**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'emr_general_examination_2';

	/**
	 * Primary Key
	 */
	var $_key = 'emr_general_examination_2_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'EmrGeneralExamination2';

	/**
	 * Handle instantiation
	 */
	function OdontoStomatologyEncounter() {
		parent::ORDataObject();
	}

	/**
	 * Overwrite persit to write datetime value
	 * @see celini/ordo/ORDataObject#persist()
	 */
	public function persist() {
		$firstTime = (((int)$this->get_id()) > 0) ? false : true;
		
		parent::persist();						
		
		$sql = "UPDATE $this->_table SET last_updated = NOW() WHERE $this->_key = " . $this->get_id();		
		$this->_execute($sql);
		if ($firstTime) {
			$sql = "UPDATE $this->_table SET encounter_date = NOW() WHERE $this->_key = " . $this->get_id();
			$this->_execute($sql);
		}
		
		return true;
	}
	
	public function getObjectFromRecordId($recordId) {		
		$sql = "SELECT $this->_key FROM $this->_table WHERE medical_record_id = $recordId";
		$res = $this->_execute($sql);
		
		$id = (!$res->EOF) ? $res->fields[$this->_key] : '';		
		return Celini::newORDO($this->_internalName, $id);
	}	
		
	
	public function getDoctorName(){
		$person	=	Celini::newORDO('Employee', $this->doctor_id);		
		return $person->getName();
	}		
}
?>
